﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Perceiveit.Xml.Converters
{
    public class UriXConverter : XConverter<Uri>
    {
        public override Uri FromString(string value)
        {
            Uri url;
            if (string.IsNullOrEmpty(value) || !Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out url))
                url = new Uri(string.Empty);

            return url;
        }

        public override string ToString(Uri value)
        {
            if (null == value)
                return string.Empty;
            else 
                return value.ToString();
        }
    }
}
